package file;

import lombok.Data;

import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * @time: 2019/11/27 13:13
 * @author: baozi
 * 字节输入流，以单个字节为最小单位
 */
@Data
public class InputStreamDemno1 {

    public static void main(String[] args) {
        try {
            //FileInputStream i=new FileInputStream("c.txt");
            //指定长度读取，把读取到的放到byte数组里
            /*byte[] b=new byte[70];
            int l=i.read(b);//m没有读取到返回-1
            System.out.println(l);
            System.out.println(new String(b));*/
            /*byte[] b=new byte[1024];
            while (i.read(b)!=-1){
                System.out.println(new String(b));
            }*/
            //单个读取
            /*int num;
            while ((num=i.read())!=-1){
                System.out.println((char)num);
            }*/
            //i.close();
            //字节流读文件中的中文可能会乱码,因为gbk对应1个中文2个字节,utf8对应1个中文3个字节
            /*FileOutputStream out1=new FileOutputStream("a.txt");
            out1.write("包子呀".getBytes());*/

            FileInputStream in=new FileInputStream("1.jpg");
            FileOutputStream out=new FileOutputStream("2.jpg");
            long start=System.currentTimeMillis();
            int i;
            while((i=in.read())!=-1){
                out.write(i);
            }
            /*byte[] b=new byte[1024];
            while(in.read(b)!=-1){
                out.write(b);
            }*/
            System.out.println("时间"+(System.currentTimeMillis()-start));
            in.close();
            out.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
